import request from "@/utils/request";
import type { OrderCreateParams, OrderCreateResult, OrderPreResult, OrderResult } from "@/types/order";
import type { ResponseType } from "@/types/response";

enum Enum {
    orderPre = "/member/order/pre",
    now = "/member/order/pre/now",
    submitOrder = "/member/order",
    orderDetail = "/member/order",
    wxPay = "/pay/wxPay/miniPay",
    payMock = "/pay/mock"
}

/*获取预付订单的接口*/
export const fetchOrderPreAPI = (): Promise<ResponseType<OrderPreResult>> => request.get<OrderPreResult, ResponseType<OrderPreResult>>(Enum.orderPre);

/*立即购买订单的接口*/
export const fetchNowOrderPreAPI = (params: { skuId: string, count: string, addressId?: string }): Promise<ResponseType<OrderPreResult>> => request.get<OrderPreResult, ResponseType<OrderPreResult>>(Enum.now, { params });

/*提交订单的接口*/
export const submitOrderAPI = (data: OrderCreateParams): Promise<ResponseType<OrderCreateResult>> => request.post<OrderCreateResult, ResponseType<OrderCreateResult>>(Enum.submitOrder, data);

/*获取订单详情的接口*/
export const fetchOrderDetailAPI = (id: string): Promise<ResponseType<OrderResult>> => request.get<OrderResult, ResponseType<OrderResult>>(`${Enum.orderDetail}/${id}`);

/*获取微信支付参数*/
export const payWxPayMiniPayAPI = (params: { orderId: string }) => request.get<any, any>(Enum.wxPay, { params });

/*模拟支付*/
export const payMockAPI = (params: { orderId: string }) => request.get(Enum.payMock, {params});
